home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / tptc17sc.zip / GETENV.INC < prev    next >
Text File  |  1988-03-25  |  767b  |  42 lines

  1.  
  2. (*
  3.  * get the value of an environment variable
  4.  *
  5.  * (C) 1987 Samuel H. Smith, 14-Dec-87 (rev. 27-Jan-88)
  6.  *
  7.  * example:  path := get_environment_var('PATH=');
  8.  *
  9.  *)
  10.  
  11. function get_environment_var(id: string): string;
  12. var
  13.    envseg:  integer;
  14.    i:       integer;
  15.    env:     string;
  16.  
  17. begin
  18.    envseg := memw[PrefixSeg:$2c];
  19.    i := 0;
  20.  
  21.    repeat
  22.       env := '';
  23.       while mem[envseg:i] <> 0 do
  24.       begin
  25.          env := env + chr(mem[envseg:i]);
  26.          i := i + 1;
  27.       end;
  28.  
  29.       if copy(env,1,length(id)) = id then
  30.       begin
  31.          get_environment_var := copy(env,length(id)+1,255);
  32.          exit;
  33.       end;
  34.  
  35.       i := i + 1;
  36.    until mem[envseg:i] = 0;
  37.  
  38. (* not found *)
  39.    get_environment_var := '';
  40. end;
  41.  
  42.